<?php
class Water_markApp extends MemberbaseApp
{
	var $_water_mark_mod;
	
	function __construct(){
		parent::__construct();
		$this->Water_markApp();
	}
	
	
	function Water_markApp(){
		$this->_water_mark_mod=&m('water_mark');
	}
	
	function index(){
		$page = $this->_get_page();
		$water_list = $this->_water_mark_mod->find(array(
				'conditions' => 'if_show=1',
				'count' => true,
				'limit' => $page['limit']
		));
		$page['item_count'] = $this->_water_mark_mod->getCount();
		$this->_format_page($page);
		$this->assign('page_info', $page);
		$this->assign('water_list', $water_list);
		$this->display('water_mark.index.html');
		$this->_curlocal(Lang::get('water_mark_manage'));
	}
	
	
	function add(){
		if(!$_POST){
			$this->display('water_mark.form.html');
			$this->_curlocal(Lang::get('water_mark_list'), 'index.php?app=water_mark&act=index',
					Lang::get('add_water'));
		}else{
			$data=array();
			$water_position=trim($_POST['water_position']);
			if (!$water_position){
				$this->show_warning('water_position_not_empty');
				return;
			}
			$data['water_position']=$water_position;
			$this->_water_mark_mod->add($data);
			if ($this->_water_mark_mod->has_error()){
				$this->show_warning($this->_water_mark_mod->get_error());
				return;
			}
			$this->show_message('添加成功',Lang::get('water_mark_list'),'index.php?app=water_mark&act=index');
		}
	}
	
	
	function edit(){
		$water_id=isset($_GET['water_id'])?$_GET['water_id']:0;
		if (!$water_id){
			$this->show_warning("没有该洗水唛位置");
			return;
		}
		if(!$_POST){
			$water_info=$this->_water_mark_mod->get($water_id);
			$this->assign('water',$water_info);
			$this->display('water_mark.form.html');
			$this->_curlocal(Lang::get('water_mark_list'), 'index.php?app=water_mark&act=index',
					Lang::get('edit_water'));
		}else{
			$data=array();
			$water_position=trim($_POST['water_position']);
			if (!$water_position){
				$this->show_warning('water_position_not_empty');
				return;
			}
			$data['water_position']=$water_position;
			$this->_water_mark_mod->edit($water_id,$data);
			if ($this->_water_mark_mod->has_error()){
				$this->show_warning($this->_water_mark_mod->get_error());
				return;
			}
			$this->show_message('编辑成功',Lang::get('water_mark_list'),'index.php?app=water_mark&act=index');
		}
	}
	
	
	function drop(){
		$water_id=isset($_GET['water_id'])?$_GET['water_id']:0;
		if (!$water_id){
			$this->show_warning("没有该洗水唛位置");
			return;
		}
		$this->_water_mark_mod->drop($water_id);
		if ($this->_water_mark_mod->has_error()){
			$this->show_warning($this->_water_mark_mod->get_error());
			return;
		}
		$this->show_message('删除成功');
	}
}